package net.fivegoods.web;

import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

import net.fivegoods.entity.impl.slim3.MissionExecutionModel;

import org.slim3.datastore.Datastore;

@Path("/executions")
public class MissionExecutions {
    
    @GET
    @Path("/{key}")
    public MissionExecutionModel get(@PathParam("key") String encodedKey) {
        return MissionExecutionModel.getByKeyString(encodedKey);
    }
    @POST
    public MissionExecutionModel create() {
        MissionExecutionModel execution = new MissionExecutionModel();
        execution.save();
        return execution;
    }
    @PUT
    public MissionExecutionModel update(@FormParam("key") String encodedKey) {
        MissionExecutionModel execution = MissionExecutionModel.getByKeyString(encodedKey);
        execution.setKey(Datastore.stringToKey(encodedKey));
        execution.save();
        return execution;
    }
    @DELETE
    @Path("/{key}")
    public void delete(@PathParam("key") String encodedKey) {
        MissionExecutionModel.deleteByKeyString(encodedKey);
    }
}
